package com.itboye.ihomebank.responsitory;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.base.BaseNetRepository;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.base.SystemMessBean;
import com.itboye.ihomebank.bean.FaBuHouseBean;
import com.itboye.ihomebank.bean.HeTongBean;
import com.itboye.ihomebank.bean.KeyBean;
import com.itboye.ihomebank.bean.MyCollectionBean;
import com.itboye.ihomebank.bean.PersonDataBean;
import com.itboye.ihomebank.bean.QianYueDetailBean;
import com.itboye.ihomebank.bean.RegisterBean;
import com.itboye.ihomebank.interfaces.IUserInterface;
import com.itboye.ihomebank.net.BaseErrorListener;
import com.itboye.ihomebank.net.BaseSuccessReqListener;
import com.itboye.ihomebank.net.ByJsonRequest.Builder;

/***
 * 请求网络类
 * 
 * @author admin
 * 
 */
public class UserRepository extends BaseNetRepository implements
		IUserInterface<PersonDataBean> {
	String api = "100";
	String loginTypeKey = "BY_User_login";// 用户登录
	String sendTypeKey = "BY_Message_send_sms";// 发送短信
	String verificationTypeKey = "BY_Message_checkCode";// 验证验证码
	String registerTypeKey = "BY_User_register";// 注册
	String backPassTypeKey = "BY_User_findPswByMobile";// 手机找回密码
	String updateTypeKey = "BY_User_update";// 更新用户信息
	String UploadPicturesTypeKey = "BY_File_upload";// 图片上传
	String systemMessage = "BY_Message_query";// 获取系统消息
	String UpdatePwdByPwd = "BY_User_updatePsw";// 修改密码（通过原密码修改）
	String FindPwdByPhone = "BY_User_findPswByMobile";// 找回密码（通过手机号码找回）
	String oritation = "BY_Config_position";// 获取方向
	String house_addKey = "BY_House_add";// 发布房源
	String renzhengKey = "BY_User_verifyApply";// 实名认证
	String messageKey = "BY_Message_query";// 消息分页查询
	String bindKeJiXia = "BY_Sciener_reg";// 绑定科技侠
	String myKey = "BY_Sciener_lock";// 查询我的钥匙
	String updateKey = "BY_Sciener_edit";// 修改钥匙名字
	String heTongParams = "BY_Contract_getParams";// 获取填写合同参数
	String tiJiaoHeTong = "BY_Contract_write";// 提交合同
	String queRenHeTong = "BY_Contract_confirm";// 确认合同
	String orderDetail = "BY_Contract_detail";// 订单详情
	String myCollection = "BY_favorites_show";// 我的收藏
	String getYwHistory="BY_Message_ywHis";//获取历史
	String siliao="BY_Message_ywPush";//私聊
	String ywContactName="BY_Message_ywRelation";//获取联系人列表
	public UserRepository(ICompleteListener iCompleteListener) {
		super(iCompleteListener);
	}

	@Override
	public void login(String userName, String pwd) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<PersonDataBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("username", userName);
		map.put("password", pwd);
		(new Builder<PersonDataBean>())
				.setTypeVerParamsAndReturnClass(loginTypeKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<PersonDataBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 发送短信
	 */
	@Override
	public void send(String phone, String code) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobile", phone);
		map.put("code_type", code);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(sendTypeKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 验证验证码
	 */
	@Override
	public void verification(String mobile, String code_type, String code) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobile", mobile);
		map.put("code_type", code_type);
		map.put("code", code);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(verificationTypeKey, apiVer,
						map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 注册
	 */
	@Override
	public void register(String reg_type, String from, String code,
			String username, String password) {
		Type type = new TypeToken<RegisterBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("reg_type", reg_type);
		map.put("from", from);
		map.put("code", code);
		map.put("username", username);
		map.put("password", password);
		(new Builder<RegisterBean>())
				.setTypeVerParamsAndReturnClass(registerTypeKey, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<RegisterBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 手机找回密码
	 */
	@Override
	public void backPass(String mobile, String code, String psw) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobile", mobile);
		map.put("code", code);
		map.put("psw", psw);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(backPassTypeKey, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 修改性别
	 */
	@Override
	public void updateSex(String uid, String sex) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("sex", sex);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(updateTypeKey, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 修改昵称
	 */
	@Override
	public void updateNickname(String uid, String nickname) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("nickname", nickname);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(updateTypeKey, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 修改头像
	 */
	@Override
	public void updateHead(String uid, String type, String image) {
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("type", type);
		map.put("image", image);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(UploadPicturesTypeKey, apiver,
						map, type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/***
	 * 得到系统配置
	 */
	@Override
	public void getConfig() {
		// TODO Auto-generated method stub
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		Map<String, Object> map = new HashMap<String, Object>();
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass("BY_Config_app", apiver, map,
						type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/***
	 * 绑定手机或者修改绑定手机
	 */
	@Override
	public void bindPhone(String uid, String phone, String code,
			String password, boolean isChange) {
		// TODO Auto-generated method stub
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		String typeKey = "";
		if (isChange) {
			typeKey = "BY_User_bind";
		} else {
			typeKey = "BY_User_changePhone";
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("mobile", phone);
		map.put("code", code);
		map.put("password", password);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(typeKey, apiver, map, type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 密码修改
	 */
	@Override
	public void updatePwdByPwd(String uid, String oldPassword,
			String newPassword) {
		// TODO Auto-generated method stub
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		Map<String, Object> map = new HashMap<String, Object>();
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(UpdatePwdByPwd, apiver, map,
						type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 手机找密
	 */
	@Override
	public void updatePwdByPhone(String uid, String mobile, String code,
			String newPassword) {
		// TODO Auto-generated method stub
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		Map<String, Object> map = new HashMap<String, Object>();
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(FindPwdByPhone, apiver, map,
						type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/***
	 * 获取系统消息
	 */
	@Override
	public void systemMessage(String uid, String msgType) {
		// TODO Auto-generated method stub
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		Map<String, Object> map = new HashMap<String, Object>();
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(systemMessage, apiver, map,
						type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getDirection() {
		// TODO Auto-generated method stub
		Type type01 = new TypeToken<String>() {
		}.getType();

		String apiver = api;
		Map<String, Object> map = new HashMap<String, Object>();
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(oritation, apiver, map, type01)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	/**
	 * 发布房源
	 */
	public void getHouseAdd(String uid, String imgs, String community_code,
			int rent_type, String contact_name, String contact_phone,
			String rent, String size, String unit, String house_floor,
			String floors, String house_decoration, String house_pay,
			String house_dir, String address, String entrust_money,
			String house_feature, String house_device, String addressdetail) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("imgs", imgs);
		map.put("community_code", community_code);
		map.put("rent_type", rent_type);
		map.put("contact_name", contact_name);
		map.put("contact_phone", contact_phone);
		map.put("rent", rent);
		map.put("size", size);
		map.put("unit", unit);
		map.put("house_floor", house_floor);
		map.put("floors", floors);
		map.put("house_decoration", house_decoration);
		map.put("house_pay", house_pay);
		map.put("house_dir", house_dir);
		map.put("address", address);
		map.put("entrust_money", entrust_money);
		map.put("house_feature", house_feature);
		map.put("house_device", house_device);
		map.put("address", addressdetail);
		// map.put("house_feature", house_feature);
		// map.put("house_device", house_device);
		// map.put("transportation", transportation);
		// map.put("education", education);
		// map.put("title", title);
		// map.put("entrust_money", entrust_money);
		// map.put("front_money", front_money);
		// map.put("service_money", service_money);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(house_addKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 实名认证
	 */
	public void getRealName(String uid, String realname, String idnumber,
			String code) {
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("realname", realname);
		map.put("idnumber", idnumber);
		map.put("code", code);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(renzhengKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	/**
	 * 消息分页查询
	 */
	@Override
	public void getSystemMess(String uid, String msg_type, String page_no,
			String page_size) {

		Type type = new TypeToken<SystemMessBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("msg_type", msg_type);
		map.put("page_no", page_no);
		map.put("page_size", page_size);

		(new Builder<SystemMessBean>())
				.setTypeVerParamsAndReturnClass(messageKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<SystemMessBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void bindKeJiXia(String uid, boolean isBind) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		// map.put("name", name);
		// map.put("pass", pass);
		if (!isBind) {
			bindKeJiXia = "BY_Sciener_unbind";
		}
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(bindKeJiXia, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void myKey(String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<KeyBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		(new Builder<KeyBean>())
				.setTypeVerParamsAndReturnClass(myKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<KeyBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void updateKey(String uid, String lockId, String alias) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("lock_id", lockId);
		map.put("alias", alias);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(updateKey, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void heTongParams(String subject) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<HeTongBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("subject", subject);
		(new Builder<List<HeTongBean>>())
				.setTypeVerParamsAndReturnClass(heTongParams, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<HeTongBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void tiJiaoHeTong(String uid, String contractNo, String params) {
		// TODO Auto-generated method stub

		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("contract_no", contractNo);
		map.put("params", params);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(tiJiaoHeTong, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void wanChengHeTong(String uid, String contractNo) {
		// TODO Auto-generated method stub

		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("contract_no", contractNo);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(queRenHeTong, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void qianyueDetail(String uid, String contractNo) {
		// TODO Auto-generated orderDetail

		Type type = new TypeToken<QianYueDetailBean>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("contract_no", contractNo);
		(new Builder<QianYueDetailBean>())
				.setTypeVerParamsAndReturnClass(orderDetail, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<QianYueDetailBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void myCollection(String uid, String status) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<MyCollectionBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("status", status);
		(new Builder<List<MyCollectionBean>>())
				.setTypeVerParamsAndReturnClass(myCollection, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<MyCollectionBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void getYWContactName(String uid, String startDate, String endDate) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<MyCollectionBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("begin", startDate);
		map.put("end", endDate);
		(new Builder<List<MyCollectionBean>>())
				.setTypeVerParamsAndReturnClass(ywContactName, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<MyCollectionBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void siLiao(String uid, String toUid, String msg) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<MyCollectionBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("to_uid", toUid);
		map.put("msg", msg);
		(new Builder<List<MyCollectionBean>>())
				.setTypeVerParamsAndReturnClass(siliao, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<MyCollectionBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getSiXinHistory(String uid, String toUid, String begin,
			String end, String count, String next) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<MyCollectionBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("to_uid", toUid);
		map.put("begin", begin);
		map.put("end", end);
		map.put("count", count);
		map.put("next", next);
		
		(new Builder<List<MyCollectionBean>>())
				.setTypeVerParamsAndReturnClass(getYwHistory, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<List<MyCollectionBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
